package com.ruoyi.biz.report.letter.controller;

import com.ruoyi.biz.report.letter.service.CategoryReportService;
import com.ruoyi.biz.report.letter.service.ReportService;
import com.ruoyi.biz.report.letter.vo.*;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * report
 *
 * @author Fei.Cong
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/letter/report")
@RequiredArgsConstructor
public class ReportSummaryController {

    private final ReportService reportService;
    private final CategoryReportService categoryReportService;

    @PreAuthorize("@ss.hasPermi('city:letter:query:report')")
    @GetMapping("/claim/summary")
    public R cityReport(ReportReq reportReq) {
        List<ReportResp> reportVOS = reportService.getCityClaimReport(reportReq);
        return R.ok(reportVOS);
    }

    @GetMapping("/homepage/summary")
    public R getHomePageSummary() {
        return R.ok(reportService.getHomePageSummary());
    }

    @GetMapping("/homepage/linechart/summary")
    public R getHomePageLineChartSummary() {
        return R.ok(reportService.getLineChartSummary());
    }

    @GetMapping("/homepage/barchart/summary")
    public R getHomePageBarChartSummary(CategoryReportReq categoryReportReq) {
        List<HomePageBarResp> chartSummary = Lists.newArrayList();
        switch (categoryReportReq.getType()) {
            case 1:
                chartSummary = reportService.getGoverBarChartSummary();
                break;
            case 2:
                chartSummary = reportService.getVisitBarChartSummary();
                break;
        }
        return R.ok(chartSummary);
    }

    @PreAuthorize("@ss.hasPermi('report:export')")
    @PostMapping("/claim/export")
    public void export(HttpServletResponse response, ReportReq reportReq) {
        List<ReportResp> reportVOS = reportService.getCityClaimReport(reportReq);
        ExcelUtil<ReportResp> util = new ExcelUtil<>(ReportResp.class);
        util.exportExcel(response, reportVOS, "认领报表");
    }
}
